package com.github.binarywang.demo.wx.mp.utils;


import com.github.binarywang.demo.wx.mp.beans.MeiPaParam;
import com.github.binarywang.demo.wx.mp.beans.WxMpUser;
import lombok.extern.slf4j.Slf4j;

/**
 * @author xiaoban
 * @date 2021/9/4 1:15 下午
 */
@Slf4j
public class FocusUtils {

    public static String getPreKey(WxMpUser mpUser) {
        if (mpUser == null) {
            throw new IllegalArgumentException("微信数据为空!");
        }

        String key = "yunfen:pre:";
        String md5;
        String nickname = mpUser.getNickname();
//        if (mpUser.getProvince()!=null){
//            nickname += mpUser.getProvince();
//        }
//        if (mpUser.getCity()!=null){
//            nickname += mpUser.getCity();
//        }
//        if (mpUser.getCountry()!=null){
//            nickname += mpUser.getCountry();
//        }
        md5 = Md5Utils.hash(nickname);
        key +=md5;
        log.info("按昵称加密 -> {} {}",nickname,md5);
        return  key;
    }

    public static String getPreKey(MeiPaParam param) {
        return getPreKey(WxMpUser.builder()
            .headimgUrl(param.getHeadimgurl())
            .nickname(param.getNickname())
            .city(param.getCity())
            .province(param.getProvince())
            .country(param.getCountry())
            .build());
    }
}
